package com.obtk.service.impl;

import com.obtk.mapper.CstActivityMapper;
import com.obtk.model.CstActivity;
import com.obtk.service.CstActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.DateFormatter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能说明
 *
 * @author Mr.Sun
 * @date 2023-04-06 14:00:23
 */
@Service
public class CstActivityServiceImpl implements CstActivityService {
    @Autowired
    private CstActivityMapper cstActivityMapper;

    @Override
    public List<CstActivity> selectCstActivity(CstActivity cstActivity) {
        return cstActivityMapper.selectCstActivity(cstActivity);
    }

    @Override
    public CstActivity selectByLkmName() {
        return  cstActivityMapper.selectByLkmName();
    }

    @Override
    public int register(CstActivity cstActivity) {
        cstActivity.setAvtStatus(1);
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(formatter.format(date));
        cstActivity.setAvtDate(new Date());
        return cstActivityMapper.insert(cstActivity);
    }

    @Override
    public CstActivity selectByAvtId(Integer avtId) {
        return cstActivityMapper.selectByAvtId(avtId);
    }

    @Override
    public int updateByCstActivityId(CstActivity cstActivity) {

        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(formatter.format(date));
        cstActivity.setAvtDate(new Date());
        return cstActivityMapper.updateByCstActivityId(cstActivity);
    }

    @Override
    public int updateStatusBatch(List<String> avtIds, Integer avtStatus) {
        Map<String,Object> params = new HashMap<String, Object>(2);
        params.put("avtIds",avtIds);
        params.put("avtStatus",avtStatus);
        return cstActivityMapper.updateStatusBatch(params);
    }
}
